<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SuggestLog extends Model
{
    use HasFactory;

    protected $table = 'sp_suggest_log';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //handle_type处理类型：1平台介入 2客服备注 3用户申请投诉 4投诉未解决(用户再次投诉) 5用户撤销投诉 6投诉已解决 7投诉已超时
    const SUGGEST_LOG_HANDLE_TYPE_PLATFORM_INTERVENE = 1; //平台介入
    const SUGGEST_LOG_HANDLE_TYPE_REMARKS = 2; //客服备注
    const SUGGEST_LOG_HANDLE_TYPE_APPLY_COMPLAINT = 3; //用户申请投诉
    const SUGGEST_LOG_HANDLE_TYPE_UNRESOLVED_COMPLAINT = 4; //投诉未解决(用户再次投诉)
    const SUGGEST_LOG_HANDLE_TYPE_CANCEL_COMPLAINT = 5; //用户撤销投诉
    const SUGGEST_LOG_HANDLE_TYPE_RESOLVED_COMPLAINT = 6; //投诉已解决
    const SUGGEST_LOG_HANDLE_TYPE_OVERTIME_COMPLAINT = 7; //投诉已超时


    const HANDLE_TYPE_LIST = array(
        '1' => array('handle_title' => '平台介入处理', 'content' => ''),
        '2' => array('handle_title' => '客服备注', 'content' => ''),
        '3' => array('handle_title' => '用户申请投诉', 'content' => '用户选择申请投诉'),
        '4' => array('handle_title' => '投诉未解决', 'content' => ''),
        '5' => array('handle_title' => '投诉已撤销', 'content' => '用户选择已撤销投诉'),
        '6' => array('handle_title' => '投诉已解决', 'content' => '用户选择已解决投诉'),
        '7' => array('handle_title' => '投诉已超时', 'content' => '由于一直未解决投诉,投诉已超时'),
    );

    //添加
    protected function addData($suggest_id, $user_id, $title, $info, $handle_type)
    {
        if ($handle_type == 1) {
            $handle_title = $title;
        } else {
            $handle_title = self::HANDLE_TYPE_LIST[$handle_type]['handle_title'];
        }
        if ($handle_type == 1 || $handle_type == 2 || $handle_type == 4) {
            $content = $info;
        } else {
            $content = self::HANDLE_TYPE_LIST[$handle_type]['content'];
        }
        $addData = array(
            'suggest_id' => $suggest_id, //投诉id
            'user_id' => $user_id, //用户id(既关联sp_member_2中的id又关联sp_other_admin中的id  根据handle_type去判断关联哪个表)
            'handle_title' => $handle_title, //处理标题
            'content' => $content, //内容
            'handle_type' => $handle_type, //处理类型：1平台介入 2客服备注 3用户申请投诉 4投诉未解决(用户再次投诉) 5用户撤销投诉 6投诉已解决 7投诉已超时
            'create_time' => date('Y-m-d H:i:s'), //添加时间
        );
        return $data = $this->insert($addData);
    }

    protected function GetSuggestLog($where, $whereNotIn)
    {
        $data = $this
            ->where($where)
            ->whereNotIn('handle_type', $whereNotIn)
            ->orderBy('create_time', 'desc')
            ->get();
        $data = $data ? $data->toArray() : [];
        return $data;
    }


}
